<?php

class FunctionController extends BaseController 
{

    public function init()
    {
        /* Initialize action controller here */
    }
    	
    public function loginAsUserAction(){
    	$referrer=$_SERVER['HTTP_REFERER'];
    	$iUser_id=$this->_request->id;
    	$sKeygen=$this->_request->keygen;
    	$sLocalKey=md5($iUser_id+123);// var_dump($sLocalKey);var_dump($sKeygen);die;
        //var_dump($sLocalKey==$sKeygen);
    	if(strpos($referrer,DOMAIN.'backend')!==false AND $sLocalKey==$sKeygen){
	    	$mUser=new User();
	   		include_once 'defined/Authenticate.php';
		  	$mAuth=new Defined_Authenticate();
	    	//$sTable='';

	    		$oUser=$mUser->getUserById($iUser_id);
	    		$username=$oUser['email'];
	    		$password=$oUser['password'];
				$sUrl="/user/edit/";
			//	$sTable='users';

	    	if($mAuth->login($username,$password)===true){
	    		
	    		header("Location: $sUrl");
				exit();
	    	}
	    	
    	}
	#	header("Location: /");
		exit();
    }

    public function indexAction()
    {
    	
		$f=isset($_GET['f'])?$_GET['f']:'';
		switch ($f){
			case 'delete_cache':
				$k=isset($_GET['k'])?$_GET['k']:'';
				Caching::remove($k);			
				var_dump($k);
			break;
			case 'delete_cache_all':
				Caching::clean();			
				var_dump('done');
			break;
				
		}
    }

    function updateAction(){
        $db = Zend_Registry::get('db');
        $list = $db->query ('update payment set created_time=orderdate,updated_time=orderdate');
        var_dump($list);
        exit;
    }
}

